package com.example.onlinereadingsystem.demos.web.util;

import org.springframework.stereotype.Component;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;

/**
 * @Description 文件读取工具类
 * @Author ljm
 * @Date 2024/11/8
 */
@Component
public class FileReaderUtil {
    public String[] fileReaderByUrl(String filePath) throws IOException {
        List<String> lines = new ArrayList<>();
        String[] res;
        BufferedReader br = new BufferedReader(new FileReader(filePath));
        String line;
        while ((line = br.readLine()) != null) {
            lines.add(line);
        }
        res = lines.toArray(new String[0]);
        return res;
    }
}
